#ifndef _OCX_CALL_FLASH_DECODE_H_
#define _OCX_CALL_FLASH_DECODE_H_
#include <string>
#define NUMBER_KEY_HEADER	L"<number>"
#define NUMBER_KEY_FOOTER	L"</number>"

#define DATE_KEY_HEADER		L"<date>"
#define DATE_KEY_FOOTER		L"</date>"

#define STRING_KEY_HEADER	L"<string>"
#define STRING_KEY_FOOTER	L"</string>"

#define INT_KEY_HEADER		L"<int>"
#define INT_KEY_FOOTER		L"</int>"
#include <time.h>
class CCallFlashResultDecode
{
	VARIANT m_var;
public:
	void getResult(VARIANT * var)
	{
		VariantClear(var);
		VariantCopy(var,&m_var);
	}
	
	CCallFlashResultDecode(LPCWSTR pResult)
	{
		VariantInit(&m_var);
		VariantClear(&m_var);
		int nStrLen = 0;
		if(StrCmpIW(pResult,L"<true/>")==0)
		{
			m_var.vt = VT_BOOL;
			m_var.boolVal = VARIANT_TRUE;
		}
		else if(StrCmpIW(pResult,L"<false/>")==0)
		{
			m_var.vt = VT_BOOL;
			m_var.boolVal = VARIANT_FALSE;
		}
		else if(StrCmpIW(pResult,L"<undefined/>")==0)
		{
			m_var.vt = VT_EMPTY;
		}
		else if(StrCmpNIW(pResult,NUMBER_KEY_HEADER,nStrLen = lstrlenW(NUMBER_KEY_HEADER))==0) 
		{
			m_var.vt = VT_R8;
			m_var.dblVal = _wtof(pResult+ nStrLen);
		}
		else if(StrCmpNIW(pResult,DATE_KEY_HEADER,nStrLen = lstrlenW(DATE_KEY_HEADER))==0) 
		{
			m_var.vt = VT_DATE;
			time_t t = _wtoi64(pResult+ nStrLen);
			tm _tm;
			localtime_s(&_tm,&t); 
			SYSTEMTIME timeDest; 
			timeDest.wYear = (WORD) (1900 + _tm.tm_year); 
			timeDest.wMonth = (WORD) (1 + _tm.tm_mon); 
			timeDest.wDayOfWeek = (WORD) _tm.tm_wday; 
			timeDest.wDay = (WORD) _tm.tm_mday; 
			timeDest.wHour = (WORD) _tm.tm_hour; 
			timeDest.wMinute = (WORD) _tm.tm_min; 
			timeDest.wSecond = (WORD) _tm.tm_sec; 
			timeDest.wMilliseconds = 0; 
			::SystemTimeToVariantTime(&timeDest, &m_var.date); 
		}
		else if(StrCmpNIW(pResult,INT_KEY_HEADER,nStrLen = lstrlenW(INT_KEY_HEADER))==0)
		{
			m_var.vt = VT_INT;
			m_var.intVal = _wtoi(pResult+ nStrLen);
		}
		else if(StrCmpNIW(pResult,STRING_KEY_HEADER,nStrLen = lstrlenW(STRING_KEY_HEADER))==0)
		{
			m_var.vt = VT_BSTR;
			LPWSTR pEnd = StrStrIW(pResult+nStrLen,STRING_KEY_FOOTER);
			m_var.bstrVal = SysAllocStringLen(pResult+nStrLen,pEnd - (pResult+nStrLen));
		}
	}
	
	virtual ~CCallFlashResultDecode()
	{
		VariantClear(&m_var);
	} 
};



#endif//_OCX_CALL_FLASH_DECODE_H_